﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">下属机构列表</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <div style="display: inline-block;">
                <select id="selBureau"></select>
            </div>
            <button class="k-button" onclick="CreateNew()"><span class="k-icon k-i-plus"></span><span>添加新的机构</span></button>
        </div>
        <div id="grid_bureau" style="text-align: center"></div>
    </div>
</div>

<script class="init">
    LocatedMenu("单位管理", "下属机构");
    var bureaus = Whale.Remote.GetEntity({
        url: "/Systems/Bureau/Gets",
        parameters: {
            withme: true
        }
    });

    $("#selBureau").kendoDropDownList({
        dataTextField: "EduName",
        dataValueField: "Guid",
        dataSource: bureaus,
        change: function (e) {
            Filter();
        }
    });

    function Filter() {
        $("#grid_bureau").data("kendoGrid").dataSource.read();
    }
</script>

<script class="grid_columns">
    var bureauFields = [{
        title: "编码",
        field: "Code",
        width: 60
    }, {
        title: "机构名称",
        field: "EduName",
        width: 150
    }, {
        title: "用户名",
        field: "User.UserName",
        width: 100
    }, {
        title: "负责人",
        field: "User.RealName",
        width: 150
    }, {
        title: "联系手机",
        field: "User.Mobile",
        width: 100
    }, {
        title: "Email",
        field: "User.Email",
        template: "#: User.Email # <a href='javascript:ChangeEmail(\"#:User.Guid#\")' class='k-icon k-i-pencil'>&nbsp;</a>",
        width: 200
    }, {
        title: "操作",
        template: "#=GetOperations(Guid)#",
        attributes: { style: "text-align:left" },
        width: 200
    }, {}];

    function GetOperations(guid) {
        var html = "<button class='k-button' onclick=\"Edit('" + guid + "')\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        html += "<button class='k-button' onclick=\"Delete('" + guid + "')\"><span class='k-icon k-i-close'></span><span>删除</span></button>";
        return html;
    }

    function CreateNew() {
        wndGeneralEdit.setOptions({ title: "添加新的机构" });
        wndGeneralEdit.refresh({ url: "/Systems/Bureau/Edit" });
        wndGeneralEdit.open();
    }

    function Edit(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改机构信息" });
            wndGeneralEdit.refresh({ url: "/Systems/Bureau/Edit/" + guid });
            wndGeneralEdit.open();
        }
    }

    function Delete(guid) {
        if (confirm("真的要删除这个机构吗？")) {
            Whale.Remote.Operation({
                url: "/Systems/Bureau/Delete",
                parameters: { guid: guid },
                success: function (result) {
                    if ($("#grid_bureau").length > 0)
                        $("#grid_bureau").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }

    function ChangeEmail(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改帐号Email" });
            wndGeneralEdit.refresh({ url: "/Accounts/User/Email/" + guid });
            wndGeneralEdit.open();
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_bureau").kendoGrid({
            columns: bureauFields,
            dataSource: Whale.dataSource({
                url: "/Systems/Bureau/Gets",
                getParameters: function () {
                    return {
                        getUser: true,
                        guid: $("#selBureau").data("kendoDropDownList").value()
                    };
                }
            }),
            pageable: false,
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });
</script>
